<?php

/**
 * @author yupoxiong<i@yufuping.com>
 */

namespace generate\field;

class KeyWords extends Field
{

    public static $html = <<<EOF
    <div class="layui-form-item">
    <label for="[FIELD_NAME]" class="layui-form-label [REQUIRED]">[FORM_NAME]</label>
    <div class="layui-input-inline">
  <div class="tags">
  <input id="[FIELD_NAME]" placeholder="回车生成标签" type="text" >
    </div>
    </div>
</div>

<script type="text/javascript">
layui.use(['inputTags'], function () {
    var inputTags = layui.inputTags;
    inputTags.render({
        elem: '#[FIELD_NAME]',
        content: [{if isset(\$data)} {foreach \$data.[FIELD_NAME] as \$vo}'{\$vo}',{/foreach}{/if}],
        name:'[FIELD_NAME]',
        done: function (value) {
        }
    })

})
</script>\n
EOF;
public static $modelAttrCode = <<<EOF
protected function get[FIELD_NAME]Attr(\$value)
{
    if(isset(\$value)&& !empty(\$value)){
        return explode(',', \$value);
    }else{
        return [];
    }
}
protected function get[FIELD_NAME]TextAttr(\$value,\$data)
{
    return \$data['[FIELD_NAME]'];
}

\n
EOF;
    public static $rules = [
        'required'   => '非空',
    ];

    public static function create($data)
    {

       return  str_replace(
            ['[FORM_NAME]', '[FIELD_NAME]', '[REQUIRED]'],
            [$data['form_name'], $data['field_name'], self::$required],
            self::$html);
    }

}